<?php 
	if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	
	class qlsp_admin_controller extends CI_Controller {
		public function __construct(){    
			parent::__construct();
			$this->load->helper("url");    
		}
		function index()
		{
			session_start();
			$this->load->library('util');
			$this->load->library('firephp');
			
			//if($this->util->checkLogin()==false) {
				//return;
			//}
			//$mataikhoan = 1;
			
			$data['bar'] = $this->load->view('bar_view',null,true);
			$data['sidemenu'] = $this->load->view('sidemenu_admin_view',null,true);
			
			$this->util->connect();
			$this->load->model('sanpham_model');

			$data['sanpham'] = $this->sanpham_model->getTatCaSP();
			$data['loaispcha'] = $this->sanpham_model->getLoaiSPCha();
			$this->load->view('qlsp_admin_view.php', $data);
			//$this->firephp->log($_SESSION['tenanh']);
		}
		
		function getSanPham_admin_ajax()
		{
			session_start();
			$this->load->library('util');
			
			//if($this->util->checkLogin()==false) {
				//return;
			//}
			//$mataikhoan = 1;
			
			$data['bar'] = $this->load->view('bar_view',null,true);
			$data['sidemenu'] = $this->load->view('sidemenu_view',null,true);
			
			$loai = $_POST['loaicha'];
			
			$this->util->connect();
			$this->load->model('sanpham_model');

			$data['sanpham'] = $this->sanpham_model->getSanPham_admin_ajax($loai);

			$this->load->view('qlsp_view_admin_ajax_sp.php', $data);
		}
		
		function getSanPham_ajax_con_admin()
		{
			session_start();
			$this->load->library('util');
			
			//if($this->util->checkLogin()==false) {
				//return;
			//}
			//$mataikhoan = 1;
			
			$data['bar'] = $this->load->view('bar_view',null,true);
			$data['sidemenu'] = $this->load->view('sidemenu_view',null,true);
			
			$loai = $_POST['loaicon'];
			$loai_cha = $_POST['loaicha'];
			
			$this->util->connect();
			$this->load->model('sanpham_model');

			$data['sanpham'] = $this->sanpham_model->getSanPham_ajax_con_admin($loai,$loai_cha);

			$this->load->view('qlsp_view_admin_ajax_sp.php', $data);
		}
		
		function getLoaiSPCon()
		{
			session_start();
			$this->load->library('util');
			
			//if($this->util->checkLogin()==false) {
				//return;
			//}
			$mataikhoan = 1;
			
			$data['bar'] = $this->load->view('bar_view',null,true);
			$data['sidemenu'] = $this->load->view('sidemenu_view',null,true);
			
			$loaicha = $_POST['loaicha'];
			
			$this->util->connect();
			$this->load->model('sanpham_model');

			$data['loaicon'] = $this->sanpham_model->getLoaiSPCon($loaicha);

			$this->load->view('qlsp_view_admin_ajax.php', $data);
		}
		
		
		public function xoasanpham($masanpham){
			session_start();
			$this->load->library('util');
			
			//if($this->util->checkLogin()==false) {
				//return;
			//}
			//$mataikhoan = 1;
			$data['bar'] = $this->load->view('bar_view',null,true);
			$data['sidemenu'] = $this->load->view('sidemenu_view',null,true);
			
			$this->util->connect();
			$this->load->model('sanpham_model');
			
			if($this->sanpham_model->xoasanpham($masanpham) == false){
				show_error("Rất tiếc! Có lỗi đã xảy ra!");
			}else{
				redirect(base_url()."index.php/qlsp_admin_controller");
			}
		}
	}